{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "706814f2",
   "metadata": {},
   "source": [
    "-----\n",
    "* 记录时间：2022.10.10/week07\n",
    "* 主题：有序的数据结构-字符串&列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2480a898",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "* 1.有序的数据结构-字符串\n",
    "* 2.有序的数据结构-列表 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0048a18",
   "metadata": {},
   "source": [
    "## 1.字符串\n",
    "> 1.1 字符串的基本内容  \n",
    "> 1.2 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "136d6604",
   "metadata": {},
   "source": [
    "### 1.1 字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e141efab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#以上解决方案#\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "057e107d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6ce786b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#三引号： 保留字符串信息的 格式信息，保留完整的数据信息#"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13f34096",
   "metadata": {},
   "source": [
    "### 1.2 关于字符串的方法以及函数\n",
    "> 1. 字符串是可以拼接的（字符串的运算），用 + 进行字符串之间的拼接  \n",
    "> 2. 字符串是有顺序的，从第一个字符开始，从0依次往后；有长度，可以用lan()方法来检测字符串长度  \n",
    "> 3. 字符串的取值：\n",
    ">> 1. 取单个值 ：从左往右（正数，第一个值是0），从右往左（负数，第一个值是-1）\n",
    ">> 2. 取多个值 ：用切片的方法,两个值作为 取值的区间\n",
    "> 4. 字符串的方法及函数\n",
    ">> 1. in 查询成员是否存在\n",
    ">> 2. str.count() 查询数量\n",
    ">> 3. str.isdigit()判断字符串是否是数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8445bdbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "nev_name = [\"小明\",\"小红\",\"张杰\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "94cc0e26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院学媒欢迎小明\n",
      "广州南方学院学媒欢迎小红\n",
      "广州南方学院学媒欢迎张杰\n",
      "广州南方学院学媒欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in nev_name:\n",
    "    print(\"广州南方学院学媒欢迎\"+i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "eb4b3c34",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院学媒欢迎小明'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院学媒欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "acd8aee2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院学媒欢迎小明'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = '广州南方学院学媒欢迎小明'\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "07110d92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b4d7e985",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ae629ce3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a5e73c6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学媒'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[6]+text[7]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "944bb17c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学媒'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 切片 的方法进行多个值取值\n",
    "text[6:8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0647d91",
   "metadata": {},
   "source": [
    "* in 查询成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "feedf376",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'广州' in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "acc26f66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'北京' in text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3254bec2",
   "metadata": {},
   "source": [
    "* str.count() 查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c9b1b1f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count('广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0d2ce6a",
   "metadata": {},
   "source": [
    "* str.isdigit()判断字符串是否是数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "11c61f71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "age_li = 19\n",
    "age_wang = '19'\n",
    "print(age_li,type(age_li))\n",
    "print(age_wang,type(age_wang))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "adcff46f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_wang.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c7c162ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4bc3a7c",
   "metadata": {},
   "source": [
    "## 2. 有序的数据结构-列表\n",
    "\n",
    "\n",
    "> 1. 列表的基本运算法则（参考：有序的数据结构的运算法则列表）\n",
    "> 2.列表的一般方法（要求：全部掌握，并且做总结在课后笔记中）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61aa8fb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：假设，有这样一个场景，我要录入/存放一个班同学的信息（名单信息），用字符串存放是否可行？\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "44cc1b9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串存放\n",
    "网二_name = '李华，小明，李晓红，小红'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "3955ed43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串取值,比较麻烦\n",
    "网二_name[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d5bf918e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "204fec92",
   "metadata": {},
   "source": [
    "* 对比字符串和列表\n",
    "> 1. 字符串是按照字符进行数据取值  \n",
    "> 2. 列表是按照元素进行数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8652e773",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_name_list = [\"李华\",\"小明\",\"李晓红\",\"小红\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7ffd8fd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网二_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "deae4afa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "b27cd3af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓红', '小红']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "824ac056",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_age_list = [19,18,19,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "22feea32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57b13708",
   "metadata": {},
   "source": [
    "### 2.2 列表的方法\n",
    "> 1.增加  \n",
    "> 2.删除  \n",
    "> 3.修改  \n",
    "> 4.查询in,count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "73bbfb83",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8ef634f",
   "metadata": {},
   "source": [
    "* 学习方法 .Tab键\n",
    "> 1. listname.Tab键 查看所有方法名称\n",
    "> 2. help(listname.function)查看其中一个方法具体操作内容\n",
    "\n",
    "> 课后练习（做一个表格，总结列表的方法）  \n",
    "\n",
    "|列表方法|Description|example|\n",
    "|  ----  | ----  | ---- |\n",
    "|append()|增加元素，增加在列表的末尾|names.append(\"doggie\")， ['Mike', 'Marry', 'Jan', 'Jack', 'doggie']|\n",
    "|Paragraph|Text|   |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "55de1e8f",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'names' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [1]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m help(\u001b[43mnames\u001b[49m\u001b[38;5;241m.\u001b[39mappend)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'names' is not defined"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "054374cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"doggie\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "cc13a6d8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'doggie']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5b466d07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "6818f7f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(1,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "e7e3f441",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Alex', 'Marry', 'Jan', 'Jack', 'doggie']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9c1237a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
